import Mock from 'mockjs'

var rolesList = Mock.mock({
  'list|3': [{
    'id|+1': 1,
    'roleCode': '0000@id',
    'roleName|1': ['超级管理员', '管理员', '普通用户'],
    description: "@cword(5,20)"
  }]
})

export default [

  // 角色分页
  {
    url: '/role/getAllList',
    type: 'post',
    response: config => {
      return {
        code: 20000,
        data: {
          list:rolesList.list,
          currentPage:1,
          pageSize:10,
          totalCount: 30,
          totalPages: 3,
        }
      }
    }
  },
  //角色删除
  {
    url: '/role/del',
    type: 'post',
    response: config => {
      const { id } = config.body
      if (!id) {
        return {
          code: 403,
          msg: '删除失败',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
        data: id
      }
    }
  },
  // 角色增加
  {
    url: '/role/add',
    type: 'post',
    response: config => {
      const { roleName } = config.body
      if (!roleName) {
        return {
          code: 20203,
          msg: 'roleName is require',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
      }
    }
  },
  // 角色修改
  {
    url: '/role/update',
    type: 'post',
    response: config => {
      const { id, roleName } = config.body
      if (!roleName || !id) {
        return {
          code: 20203,
          msg: 'id and roleName is require',
          data: null
        }
      }
      return {
        code: 20000,
        msg: '处理成功',
      }
    }
  },
  // 角色分页
  {
    url: '/role/getPageList',
    type: 'post',
    response: config => {
      let { pageSize = 10, currentPage = 1 } = config.body
      const total = rolesList.list.length
      let list = rolesList.list.slice(pageSize * (currentPage - 1), currentPage * pageSize)
      return {
        code: 20000,
        data: {
          list,
          currentPage,
          pageSize,
          totalCount: total,
          totalPages: (total + pageSize - 1) / pageSize,
        }
      }
    }
  },
]